<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- 视口标签 -->
<meta name="viewport"
	content="width=device-width, initial-scale=1, user-scalable=no" />
<!-- 删除苹果默认的工具栏和菜单栏 -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- 设置苹果工具栏颜色 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- 忽略页面中的数字识别为电话，忽略email识别 -->
<meta name="format-detection" content="telphone=no, email=no" />
<!-- 启用360浏览器的极速模式(webkit) -->
<meta name="renderer" content="webkit">
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
<meta name="HandheldFriendly" content="true">
<!-- 微软的老式浏览器 -->
<meta name="MobileOptimized" content="320">
<!-- uc强制竖屏 -->
<meta name="screen-orientation" content="portrait">
<!-- QQ强制竖屏 -->
<meta name="x5-orientation" content="portrait">
<!-- UC应用模式 -->
<meta name="browsermode" content="application">
<!-- QQ应用模式 -->
<meta name="x5-page-mode" content="app">
<!-- windows phone 点击无高光 -->
<meta name="msapplication-tap-highlight" content="no">
<!-- 适应移动端end -->
<link rel="stylesheet" type="text/css"
	href="${path }/resource/css/base.css" />
<link rel="stylesheet" type="text/css"
	href="${path }/resource/css/index.css" />
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/plugin/TouchSlide.1.1.js"></script>
<title>会员中心—我的优惠券</title>
</head>
<body>
	<div class="wrap">
		<section class="add_content" onclick="addCoupon()">
			<i class="add_icon"></i> <span class="color_h">添加优惠劵</span>
		</section>
		<c:forEach items="${couponList}" var="coupon">
			<section class="yhj_content">
				<c:if test="${coupon.couponState eq '1'}">
					<div class="yhj_left">
						<p>￥${coupon.disCouponRule.couponRuleCut}</p>
						<p>满${coupon.disCouponRule.couponRuleFull}元可用</p>
					</div>
					<div class="yhj_right">
						<div class="yhj_right_top">
							<span>购物优惠劵</span> <span class="share_icon" id="${coupon.couponId}"></span>
						</div>
						<p>
							有效期：
							<fmt:formatDate pattern='yyyy-MM-dd'
								value='${coupon.disCouponRule.couponRuleStart}' />
						</p>
						<p>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至：
							<fmt:formatDate pattern='yyyy-MM-dd'
								value='${coupon.disCouponRule.couponRuleEnd}' />
						</p>
					</div>
				</c:if>
				<c:if test="${coupon.couponState eq '2'}">
					<div class="yhj_left">
						<p>￥${coupon.disCouponRule.couponRuleCut}</p>
						<p>满${coupon.disCouponRule.couponRuleFull}元可用</p>
					</div>
					<div class="yhj_right">
						<div class="yhj_right_top">
							<span>购物优惠劵</span><span>已分享</span>
						</div>
						<p>
							有效期：
							<fmt:formatDate pattern='yyyy-MM-dd'
								value='${coupon.disCouponRule.couponRuleStart}' />
						</p>
						<p>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至：
							<fmt:formatDate pattern='yyyy-MM-dd'
								value='${coupon.disCouponRule.couponRuleEnd}' />
						</p>
					</div>
				</c:if>
				<c:if test="${coupon.couponState eq '3'}">
					<div class="yhj_left bg_sx">
						<p>￥${coupon.disCouponRule.couponRuleCut}</p>
						<p>满${coupon.disCouponRule.couponRuleFull}元可用</p>
					</div>
					<div class="yhj_right color_sx">
						<div class="yhj_right_top">
							<span>购物优惠劵</span><span>已使用</span>
						</div>
						<p>
							有效期：
							<fmt:formatDate pattern='yyyy-MM-dd'
								value='${coupon.disCouponRule.couponRuleStart}' />
						</p>
						<p>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至：
							<fmt:formatDate pattern='yyyy-MM-dd'
								value='${coupon.disCouponRule.couponRuleEnd}' />
						</p>
					</div>
				</c:if>
			</section>
		</c:forEach>
	</div>

	<div id="hidelayer" style="display: none;">
		<div style="padding: 20px 50px;">
			<select class="form-control autoFull select2" name="couponRuleId"
				data-url="${path}/app/users/getAllCouponRules"
				style="width: 100%; height: 2.5rem; font-size: 1.5rem;"
				data-value="couponRuleId" data-filed="couponRuleName">
			</select>
		</div>
	</div>
	<script type="text/javascript"
		src="${path }/resource/js/systools/MTools.js"></script>
	<script type="text/javascript"
		src="${path }/resource/js/systools/AjaxProxy.js"></script>
	<script type="text/javascript"
		src="${path }/resource/plugin/layer/layer.js"></script>
	<script type="text/javascript">
		MTools.autoFullSelect();

		function addCoupon() {
			layer.open({
				type : 1,
				title : '选择规则',
				content : $('#hidelayer').html(),
				btn : [ '确认', '取消' ],
				yes : function(index, layero) {
					//按钮【按钮一】的回调
					var select = layero.find('select[name="couponRuleId"]');
					$.ajax({
						type : 'POST',
						url : '${path}/app/users/createCoupon',
						data : {
							couponRuleId : select.val()
						},
						dataType : 'json',
						async : false,
						success : function(res) {
							if (res && res.status == 'ok') {
								layer.msg(res.info, {
									icon : 1,
									time : 1000
								});
								setTimeout('location.reload(true)', 1000);
							} else {
								layer.msg(res.info, {
									icon : 2,
									time : 1000
								});
							}
						}
					})
					layer.close(index);
				},
				btn2 : function(index, layero) {
					//按钮【按钮二】的回调
					//return false; 开启该代码可禁止点击该按钮关闭
				},
				cancel : function() {
					//右上角关闭回调
					//return false 开启该代码可禁止点击该按钮关闭
				}
			});
		}

// 		var timeout = undefined;
		$('.share_icon').each(function(){
// 			this.addEventListener('touchstart', function(event) {
// 				timeout = setTimeout('share()', 800);
// 			}, false);
// 			this.addEventListener('touchend', function(event) {
// 				clearTimeout(timeout);
// 			}, false);
			this.addEventListener('click', function(e) {
				window.location.href = '${path}/app/toCouponDetail?id=' + this.id;
			})
		})
	</script>
</body>
</html>